class Main extends egret.DisplayObjectContainer {

    /****************************** 资源与loading配置 ***************************/

    static resUrl: string   = "resource/default.res.json";
    static resRoot: string  = "resource/";
    static resGroup: string = "main";
    static loading: any     = LoadingUI;


    private stageWidth: number;
    private stageHeight: number;


    /************************************* 初始化构造 *************************************/

    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.changeScene, this);
    }


    /****************************** 切换主场景 ***************************/

    private changeScene() {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.changeScene, this);
        ScenesMgmt.create(this.stage);
        ScenesMgmt.self.changeScene(Main, this.createScene, this);
    }


    /************************************* 创建游戏场景 *************************************/

    private createScene() {
        //背景
        var backgroundImg = creatImg("blue_bg_png");
        this.addChild(backgroundImg);
        //创建背景图片
        var shuiwen = creatImg("shuiwen_png");
        shuiwen.width = 640;
        shuiwen.height = 1136;
        shuiwen.scaleX = 1.01;
        shuiwen.scaleY = 1.1;
        shuiwen.anchorOffsetX = this.stage.$stageWidth * .5;
        shuiwen.anchorOffsetY = this.stage.$stageHeight * .5;
        shuiwen.x = shuiwen.width * .5;
        shuiwen.y = shuiwen.height * .5;
        this.addChild(shuiwen);

        // //遮罩
        // var rect:egret.Rectangle = new egret.Rectangle(-60,-60,640,1136);
        // this.stage.mask = rect;

        var move = egret.Tween.get(shuiwen, { loop: true });
        move.to({ x: shuiwen.width * .5 + 5, y: shuiwen.height * .5 + 60 }, 7000).wait(500).to({ x: shuiwen.width * .5, y: shuiwen.height * .5 }, 7000);
        //运动员背景
        var playerBg = creatImg("player_png");
        playerBg.y = 128;
        this.addChild(playerBg);
        //创建文字图片
        var titleImg = creatImg("title_png");
        titleImg.x = 45;
        titleImg.y = 45;
        this.addChild(titleImg);
        //创建开始按钮
        var textStart = creatText("开始", 60, 0xfe3c63, "start_bg_png", 303, 120);
        textStart.x = (this.$stage.stageWidth - textStart.width) * 0.5;
        textStart.y = this.stage.stageHeight - 120 - 115;
        this.addChild(textStart);
        textStart.touchEnabled = true;
        textStart.addEventListener(egret.TouchEvent.TOUCH_BEGIN, function () {
                egret.Tween.get(textStart).to({ alpha: .8 }, 100);
                ScenesMgmt.self.changeScene(Swim, (scene) => {
                        scene.setUserHead("resource/assets/game/touxiang.png");
                });
        }, this)
        textStart.addEventListener(egret.TouchEvent.TOUCH_END, function () {
                egret.Tween.get(textStart).to({ alpha: 1 }, 100);
        }, this)
        //创建信息弹出层
        let dialogs: egret.DisplayObjectContainer = Dialogs.message([
                {
                        title: "游戏规则",
                        content: "1.每玩一次游戏可获得一次抽奖机会；\n2.游戏排名越靠前，中奖几率越大。"
                },
                {
                        title: "奖品设置",
                        content: "1.小米运动手环\n2.超轻户外背包\n3.乐扣便携运动水壶\n4.迪卡侬透气速干T恤\n5.迪卡侬速干毛巾\n6.多功能运动腰包\n7.安联运动意外保障计划（7天）"
                }
        ]);
        //创建规则信息
        var textrule = creatText("游戏规则", 30, 0xffffff, "", 120, 100);
        textrule.x = (this.$stage.stageWidth - textrule.width) * 0.5;
        textrule.y = this.stage.stageHeight - 130;
        this.addChild(textrule);
        textrule.touchEnabled = true;
        textrule.addEventListener(egret.TouchEvent.TOUCH_BEGIN, function () {
                Effect.bounceIn(dialogs, this.stage);
        }, this);
    }
        
}


